package com.woniuxy.movice.mapper;

import java.util.List;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.woniuxy.movice.dto.Round ;
import com.woniuxy.movice.dto.RoundDate;

import org.apache.ibatis.annotations.Param;

import com.woniuxy.movice.entity.Rounds;

public interface RoundMapper {

	Rounds findRoundById(Integer pid);
	
    int updateLayout(@Param("id")Integer id,@Param("seats")String seats);

	@Select("select * from round where yid=#{yid} and mid=#{mid} and pstart>#{start} and pstart<#{end} and pstart>#{now} order by pstart")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mid", property = "mid"),
		@Result(column = "yid", property = "yid"), @Result(column = "pstart", property = "pstart"),
		@Result(column = "pend", property = "pend"), @Result(column = "pprice", property = "pprice"),
		@Result(column = "ytid", property = "ytid"),@Result(column = "ytlayout", property = "ytlayout"), 
		@Result(column = "mid", property = "language", one = @One(select = "com.woniuxy.movice.mapper.MovieMapper.findLanguageByMid")),
		@Result(column = "ytid", property = "ytname", one = @One(select = "com.woniuxy.movice.mapper.MovieHallMapper.findYtnameByYtid"))})
	List<Round> findRoundByMidAndYid(Round round);

	@Select("select * from round where id=#{cid}")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mid", property = "mid"),
		@Result(column = "yid", property = "yid"), @Result(column = "pstart", property = "pstart"),
		@Result(column = "pend", property = "pend"), @Result(column = "pprice", property = "pprice"),
		@Result(column = "ytid", property = "ytid"),@Result(column = "ytlayout", property = "ytlayout"), 
		@Result(column = "mid", property = "language", one = @One(select = "com.woniuxy.movice.mapper.MovieMapper.findLanguageByMid")),
		@Result(column = "ytid", property = "ytname", one = @One(select = "com.woniuxy.movice.mapper.MovieHallMapper.findYtnameByYtid"))})
	Round findRoundByCid(Integer cid);

	@Select("select DATE_FORMAT(FLOOR(pstart),'%Y年%m月%d日')roundDate from round where yid=#{yid} and mid=#{mid} and pstart>#{now} GROUP BY roundDate")
	List<RoundDate> showRoundDate(Round round);
	
}
